package 二叉树;

public class LC_98验证二叉搜索树 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public boolean isValidBST(TreeNode root) {
        if(root==null) return true;
        TreeNode pre=null;
        //左
        boolean left=isValidBST(root.left);
        //中
        if(pre!=null && pre.val>=root.val)
            return false;
        pre=root;
        //右
        boolean right=isValidBST(root.right);
        return left&&right;
    }
}
